This plug-in shows just how easy it is to use the Photoshop plug-in interface now
available to Image users. I have taken the example provided by Adobe and have
removed some unneccessary code and added my own. There is nothing here for experienced programmers, rather this is an example of how a casual or beginning MAC programmer can get something useful done while learning about the Macintosh. The complete Think-C 5.04 project is here with all code and resources.
Before proceeding one should read the documentation in the Plug-In Developers
Kit available from Zippy. Especially if you want to work with very large images and
spool them in a little at a time.
This plug-in aquires an image from a file from a Lynxx CCD camera. This camera saves 12-bit images, ( that have been transferred from a DOS disk) packed in the following format: 00000000 XXXX0000 XXXXXXXX. Three bytes for two pixels, where the first byte is the lsb's of the first pixel, the third byte is the lsb's of the second pixel, and
the middle byte contains the msb's as shown. This plug-in unscrambles the data
and passes the information on to the calling application as an 8-bit image. This camera
also has a pixel aspect ratio of 1 to 1.16 which could be corrected by the plug-in, but
since both Image and Photoshop have scaling, I didn't bother for now.
The image is only 192 X 165 pixels, so the entire image is read from the disk and
stored while it is processed. For very large images the plug-in would probably want to
read the file one piece at a time and pass it on in like manner. The example in the
developer's kit documents how to do this. One additional thing to keep in mind is to
be careful not to leave any files open in case of user cancellation.
Experimentally I have tried to allocate huge blocks (4 Meg) of memory from a plug-in
without problem. I have also tried file getting/saveing from all three types of plug-ins. This means some pretty sophisticated things could be managed from the
plug-in environment.
The process goes basicly like this:
1 The calling application enters the plug-in with the DoPrepare() routine
here you can initialize your globals and allocate your memory. I have
allocated a handle big enough to hold the entire image as 16-bit numbers,
making it simple to later implement rescaling. Also in this case the user is
prompted for a file and the appropriate information is saved. Remember also,
it is important to be able to recover from file errors. A plug-in reading, for
instance, a compressed TIFF file might want to build some tables or do other prep
here.
2 The DoStart () routine puts up a modal dialog giving the user a chance to control
the acqusition process. There are many possibilities here. I show the user the
min and max values and allow them to be changed. Another option would be to
plot a histogram and allow selection graphically of the range of values to be
converted, possibly with gamma correction. My intention eventually is to have
the user prompted upon reentry for rescaling of the last image or getting a
new image.
3 The image is actually processed by the DoContinue () routine. The paradyme
here is rows and columns, left to right and top to bottom. Progress is measured in
this manner. After each row there is a test for user cancellation and an update
of a standard progress thermometer. It is up to the calling application to provide
these routines. Here the image is scaled to 8-bits of dynamic range and passed
on.
4 A friendly plug-in will release its memory at completion when DoFinish () is
called. Of course, a command like rescale could be implemented by leaving the
the image in memory, avoiding the need to read it again.